﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DatabaseModule;

namespace EMC
{
   public class FileManagement
    {
        private DAO dbConn;

        private databaseConfiguration config;

        public FileManagement(databaseConfiguration dbConfig)
        {
            this.config = dbConfig;
            dbConn = dbFactory.newDB(config.dbType, config.dbConnectionString);
        }

        public void addfile(string file_name, string description, string userid)
        {

            KeyValues fieldVals = new KeyValues();

            fieldVals.Add(config.tableFiles_UserID, userid);
            fieldVals.Add(config.tableFiles_Filename, file_name);
            fieldVals.Add(config.tableFiles_Description, description);

        }

        // Assuming that for unentered fields the an empty string is passed
        public void editFile(string file_name, string description, string userid, string locale)
        {

            KeyValues fieldVals = new KeyValues();
            KeyValues keyVals = new KeyValues();
            string empty = "";

            if (description != empty)
            {

                keyVals.Add(config.tableFiles_Description, description);

            }
            if (userid != empty)
            {

                keyVals.Add(config.tableFiles_UserID, userid);

            }

            fieldVals.Add(config.tableFiles_Filename, file_name);
            dbConn.SetVerboseMode(true);
            dbConn.UpdateRows(config.tableUsers, keyVals, fieldVals);

        }
        public void removeFile(string file_name)
        {

        }
    }
}